<?php
namespace api\controllers;

use api\models\Content;
use Faker\Provider\Uuid;

/**
 * Class ContentController
 */
class ContentController extends \api\common\controllers\BaseController{

    public $modelClass = 'api\models\Content';

    public function actionFind(){
        $data = \Yii::$app->request->get();
        $model = new Content();
        $model->setScenario('find');
        static::$FIELDS_KEY = 'find';
        $model->load($data,'');
        if($model->validate()){
            $model = $model::find()->where(['content_id'=>$data['content_id']])->one();
//            $model = $model->getCate();
            if($model==null){
                static::$CODE = 1005;
                static::$STATUSTEXT = '查询不到数据';
            }
        }
        return $model;
    }

    public function actionReleaseContent(){
        $data = \Yii::$app->request->post();
        $model = new Content();
        $model->setScenario('release_content');
        static::$FIELDS_KEY = 'release_content';
        $model->load($data,'');
        if($model->validate()){
            $model->user_id = $data['user_id'];
            $model->content_id = Uuid::uuid();
            if(!$model->insert(false)){
                static::$CODE = 1004;
                static::$STATUSTEXT = '发布失败';
            }
        }
        return $model;
    }

    protected function verbs()
    {
        $verbs = parent::verbs(); // TODO: Change the autogenerated stub
        $verbs['find'] = ['GET'];
        $verbs['release_content'] = ['POST'];
        return $verbs;
    }
}
